package com.atguigu.gmall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsWebFilter(){
        CorsConfiguration configration = new CorsConfiguration();
        configration.addAllowedMethod("*");
        configration.addAllowedHeader("*");
        configration.addAllowedOrigin("http://manager.gmall.com");
        configration.addAllowedOrigin("http://localhost:1000");
        configration.addAllowedOrigin("http://www.gmall.com");
        configration.addAllowedOrigin("http://gmall.com");
        configration.setAllowCredentials(true);
        UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
        configurationSource.registerCorsConfiguration("/**",configration);
        CorsWebFilter corsWebFilter = new CorsWebFilter(configurationSource);
        return corsWebFilter;
    }
}
